﻿using System;
using System.Globalization;

namespace Vk.Methods.Common
{
    public class ApiEnum<TEnum> where TEnum : struct, IConvertible
    {
        public int Value { get; }

        public ApiEnum(TEnum enumeration)
        {
            if (!(enumeration is Enum))
            {
                throw new ArgumentException("enumeration should be Enum");
            }
            Value = enumeration.ToInt32(CultureInfo.InvariantCulture);
        }

        public override string ToString()
        {
            return Value.ToString();
        }

        public static implicit operator int(ApiEnum<TEnum> apiEnum)
        {
            return apiEnum.Value;
        }
    }

    public class ApiStringEnum<TEnum> where TEnum : struct, IConvertible
    {
        public TEnum Enumeration { get; set; }
        public string Value { get; }

        public ApiStringEnum(TEnum enumeration)
        {
            Enumeration = enumeration;
            if (!(enumeration is Enum))
            {
                throw new ArgumentException("enumeration should be Enum");
            }
            Value = Enum.Format(typeof(TEnum), enumeration, "G");

            //Convert from camel case to snake case
            //Combine a letter with its index and then select indices of big ones
            Value = Value.ToSnakeCase();
        }

        public override string ToString()
        {
            return Value;
        }

        public static implicit operator string(ApiStringEnum<TEnum> stringEnum)
        {
            return stringEnum.Value;
        }
    }
}